#ifndef _BUFFER_H
#define _BUFFER_H

#include "list.h"
#include "tabmap.h"

#define TRUE 1
#define FALSE 0

typedef struct buf {
    char *data;
    int len;
    int cap;
    tabmap_t *tabmap;
    int last_modified_pos;
    struct list_head list;
} buf_t;

buf_t * buf_new(void);
void buf_free(buf_t *buf);
void buf_create_buf_noundo(int offset);
void buf_create_buf(int offset);
buf_t * buf_prev(buf_t *buf);
buf_t * buf_prev_circular(buf_t *buf);
buf_t * buf_next(buf_t *buf);
buf_t * buf_next_circular(buf_t *buf);
void buf_current_prev(void);
void buf_current_next(void);
void buf_to_head(void);
void buf_to_tail(void);
int buf_inserts_noundo(buf_t *buf, char *data, int pos);
int buf_inserts(buf_t *buf, char *data, int pos);
int buf_insertc_noundo(buf_t *buf, char ch, int pos);
int buf_insertc(buf_t *buf, char ch, int pos);
int buf_appends_noundo(buf_t *but, char *data);
int buf_appends(buf_t *but, char *data);
int buf_appendc_noundo(buf_t *buf, char ch);
int buf_appendc(buf_t *buf, char ch);
int buf_delete_noundo(buf_t *buf, int start, int end);
int buf_delete(buf_t *buf, int start, int end);
int buf_replace_noundo(buf_t *buf, int start, int end, char *data);
int buf_replace(buf_t *buf, int start, int end, char *data);
int buf_delete_buf_noundo(buf_t *buf, int merge);
int buf_delete_buf(buf_t *buf);
void buf_restore_buf_noundo(buf_t *buf, int len);
buf_t * buf_head_buf(void);
buf_t * buf_copy_buf(buf_t *buf);
int buf_remove_buf(buf_t *buf);
void buf_insert_buf(buf_t *buf, buf_t *prev_buf);
void buf_start_cmds(void);
void buf_finish_cmds(void);
void buf_clear_bufs(buf_t *buf_head);

#endif /* _BUFFER_H */
